<?php
namespace Admin\Controller;
use Think\Controller;
require "./Application/Admin/Common/Common/function.php";
class KindController extends Controller {

    public function _initialize() {
        if (empty($_SESSION['user'])) {
           $this->error('请登入',U('Admin/Login/login'));
        }
    }


    public function index(){
        $this->display();
    }


    public function add(){
        $datas=M('article_kind');
        $datas->create();
        if($datas->add()){
           $this->success("添加成功",U('Admin/Kind/showinfo'));
        }else{
          $this->error("添加失败");
        }
    }

    // 分类管理列表显示页
    public function showinfo(){
        $m = M('article_kind');      
        $count = $m -> count();
        $p = getpage($count,4);
        $list = $m->field(true)->order('id')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('str1', $list); // 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display();
    }

    // 分类删除
    public function dele(){
        $m = M('article_kind');      
        $id = I('get.id');
        $str = $m->where('id='.$id)->delete();
        $str1 = M("article_content")->where('kid='.$id)->delete();
        if($str||$str1){
            $this->success("删除成功",U('Admin/Kind/showinfo'));
        }else{
            $this->error("删除失败");
        }
    }

    //分类修改显示界面
    public function edit(){
        $id = I('get.id');
        $m = M('article_kind');
        $str = $m->where('id='.$id)->find();
        $this -> assign('str',$str);
        $this -> display();

    }


    //分类修改提交
     public function edit_do(){
        $datas = M('article_kind');
        $id = I('POST.id');
        $datas->king=I('post.king');
        $datas->explanation=I('post.content');
        $str = $datas->where('id='.$id)->save();
        if($str){
            $this->success('修改成功',U('Admin/Kind/showinfo'));
        }else{
            $this->error('修改失败');
        }

    }
























}